package lesson02;

public class TestMain5 {

	public static void main(String[] args) {
		String str = "";
		String str2 = str + "aaa"; //  多创建对象了，效率低 

		String str1 = new String("aaa");
		
		System.out.println(str1 == str);
		System.out.println(str == str2);
		System.out.println(str.equals(str2)); // 字符串比较必须equals
		
//		StringBuffer线程安全， Stringbuilder非线程安全
		StringBuilder sb = new StringBuilder();
		sb.append("aaa");  // 		

		StringBuffer sb1 = new StringBuffer();
		sb1.append("aaa");  //
		
		// Thread[main,5,main]
		System.out.println(Thread.currentThread());
		new Thread(() -> {
			for (int i = 0; i < 200; i++) {
				System.out.println(Thread.currentThread().getName() + "@" + i);
			}
		}, "线程1").start();
		new Thread(() -> {
			for (int i = 0; i < 200; i++) {
				System.out.println(Thread.currentThread().getName() + "@" + i);
			}
		}, "线程2").start();
		new Thread(() -> {
			for (int i = 0; i < 200; i++) {
				System.out.println(Thread.currentThread().getName() + "@" + i);
			}
		}, "线程3").start();
	}
}
